<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
session_start();
require ("inc.php");
$db_admin    = &new db($scfg['db']['admin']);
$rows  = 20;
$page  = (int)($_REQUEST['page']?$_REQUEST['page']:1);
admin_core::check("ads@index");

/* 以下是程序部份 */
$db_admin = &new db($scfg['db']['admin']);
$table 	  = 'ad_index_txt_ad';
if($_POST || $_GET['act'] == 'del')
{
	$act = $_REQUEST['act'];
	//print_r($_POST);
	if($act == 'modify')
	{
		$id 	= (int)$_REQUEST['id'];
		$bind 	= array(
			'subject'=>$_POST['subject'],
			'url' =>$_POST['url'],
			'red' =>$_POST['red'],
			'save_time'=>time(),
			'author'=>$_POST['author'],
		);
		$rs = $db_admin->update($table,$bind," id =? ",$id);
		if($rs)
		{
		 	echo g::msg("成功：更新成功!");			
		}else
		{
		    echo g::msg("提示：没有更新！可能是你没有新的改动，如改动请稍重试！");
		}
	}elseif($act == 'add')
	{
		$bind 	= array(
			'subject'=>$_POST['subject'],
			'url' =>$_POST['url'],
			'red' =>$_POST['red'],
			'save_time'=>time(),
			'author'=>$_POST['author'],
		);
		$id = $db_admin->insert($table,$bind);
		if($id)
		{		 	 
			echo g::msg("成功：添加有成功!");
			g::gowin("?");
			exit();
		}else
		{
		    echo g::msg("提示：系統忙请稍后重试!");
		}
	}elseif($act == 'del')
	{
		$id = (int)$_REQUEST['id'];
		if($id)
		{
		 	$rs = $db_admin->delete($table," id =? ",$id);
			//echo  $db_help->getsql();
			//exit();
		 	if($rs)
		 	{
		 	    $fileName = UP_IMG_DIR."adm/index_big_img/".$id.".jpg";
				unlink($fileName);
				echo g::msg("成功：删除成功！");
		 	}else
		 	{
		 	 	echo g::msg("失败：不存在，或系统忙请稍后再试!");   
		 	}    
		}else
		{
		    echo g::msg("提示：参数有误，请误非法操作!");
		}
		g::gowin();
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link  href="static/admincp.css" rel="stylesheet" type="text/css" id="css">
<script src="Script/lib.js" 	type="text/javascript"></script>
<script src="Script/lib.ext.js" type="text/javascript"></script>
<script src="Script/lib.ext.oAdmin.js" type="text/javascript"></script>
<script type="text/javascript">
if(typeof XypForm == "undefined")
{
	_.r('<script src="static/xypform/xypfrom.js" type="text/javascript"></sc'+'ript>');
	_.r('<link  href="static/xypform/xypform.css" rel="stylesheet" type="text/css">');
}
var collapsed = $.cookie('DTh_collapse');
function collapse_change(menucount)
{
	if(_.e('menu_' + menucount).style.display == 'none') 
	{
		_.e('menu_' + menucount).style.display = '';collapsed = collapsed.replace('[' + menucount + ']' , '');
		_.e('menuimg_' + menucount).src = 'static/img/menu_reduce.gif';
	} else 
	{
		_.e('menu_' + menucount).style.display = 'none';collapsed += '[' + menucount + ']';
		_.e('menuimg_' + menucount).src = 'static/img/menu_add.gif';
	}
	$.cookie('DTh_collapse', collapsed, 2592000);
}
</script>
</head>
<body leftmargin="10" topmargin="10">
<?

//////////////////////////////////////////////////////////////////////////////////
$act = $_GET['act'];
if($act == 'list' || empty($act))
{
    $where      = array();
    $pg			= pg::sp($db_admin,$table,$where,$page,$rows);
	$rs 		= $db_admin->dataArray("select * from {$table} {$where['where']} order by id desc limit {$pg['begin']},".$rows,$where['bind']);
?>
<table width="100%" border="0" cellpadding="2" cellspacing="6">
  <tr>
    <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">         
          <tr class="header">
	<td colspan="4" class="tbhead">注册下的文字 - 管理</td>
  </tr>
  <tr class="_data_" style="font-weight:bold;">
	<td width="65%">標題</td>
	<td width="10%">录入者</td>
    <td width="17%">时间</td>
    <td width="8%">操作</td>
  </tr>
  <?
   foreach($rs as &$v)
   {  
  ?>
  <tr class="_data_">
    <td align="left"><a href="<?=$v['url']?>" target="_blank"><font style="font-size:14px; <?=($v['red']?'color:#FF0000':'')?>" ><?=$v['subject']?></font></a></td>
    <td align="left"><?=$v['author']?></td>
    <td align="left">录入:<?=g::time($v['save_time'],1)?><br /></td>
    <td align="left"><a href="?act=modify&id=<?=$v['id']?>">修改</a> <a href="?act=del&id=<?=$v['id']?>" onClick="return oAdmin.msgYn();">刪除</a></td>
  </tr>
  <?
   }
  ?>
</table>
        </td>
  </tr>
</table>
<br />
<form method="post" enctype="multipart/form-data" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="2" cellspacing="6">
  <tr>
    <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">         
          <tr class="header">
        <td colspan="2" class="tbhead">添加 - 注册下的文字</td>
    </tr>
	  <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left"> 
		 <input name="subject" require="1" value="<?=$_POST['subject']?>" type="text" id="subject" size="50" maxlength="32">
		 <label>
		 <input name="red" type="checkbox" id="red" value="1" />
		 </label>
		 套红</td>
	  </tr>
      <tr class="_data_">
        <td width="14%" align="right">录入者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="30" maxlength="30" value="<?=admin_main::getMaster()?>"></td>
      </tr>
  <tr class="_data_">
        <td align="right" valign="top">目标URL：</td>
        <td align="left">
      <input name="url" type="text" id="url" size="50" /></td>
      </tr>
  <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">
        
        <input name="act" type="hidden" id="act" value="add"></td>
      </tr>
</table>
        </td>
  </tr>
</table>
</form>

<?
}elseif($act == 'modify')
{
	$id = (int)$_REQUEST['id'];
	$rs = $db_admin->row("select * from {$table} where id=? ",$id);
?>
<form method="post" enctype="multipart/form-data" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="2" cellspacing="6">
  <tr>
    <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableborder">         
          <tr class="header">
        <td colspan="2" class="tbhead">更改 - 注册下的文字</td>
    </tr>
	  <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left">
		 <input name="subject" require="1" value="<?=$rs['subject']?>" type="text" id="subject" size="50" maxlength="32">
		 <label>
		 <input name="red" type="checkbox" <?=($rs['red']?' checked="checked"':'')?> id="red" value="1" />
         </label>
套红</td>
	  </tr>
      <tr class="_data_">
        <td width="14%" align="right">录入者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="20" maxlength="30" value="<?=$rs['author']?>"></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">目标URL：</td>
        <td align="left">
        <input name="url" type="text"  value="<?=$rs['url']?>" id="url" size="50" /></td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">        
        <input name="act" type="hidden" id="act" value="modify"></td>
      </tr>
</table>
        </td>
  </tr>
</table>
</form>
<? }?>
<? include("s_tpl.copyright.php"); ?>
</body>
</html>